﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Empires.PL.Web.Models;

namespace Empires.PL.Web.Controllers
{
    public class AccountController : Controller
    {
        //
        // GET: /Account/
        [HttpPost]
        public int Login(string username, string password, string remember)
        {
            return Empires.PL.ServiceClient.AppUserServiceClient.UserLogin(username, password, Convert.ToBoolean(remember)) ? 1 : 0;
        }
        public void LogOut()
        {
            FormsAuthentication.SignOut();
        }
        public int CheckUserUnique(string username)
        {
            return PL.ServiceClient.AppUserServiceClient.ExistUserName(username);
        }
        public ActionResult Register()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Register(RegisterModel mode)
        {
            int reuslt = PL.ServiceClient.AppUserServiceClient.NewUserRegister(
                mode.username, mode.password, mode.nickname, mode.sex == 0 ? false : true, mode.birthday, mode.contact, mode.appellaction, mode.address);
            if (mode.opensite.ToLower() == "on")
            {
                return RedirectToAction("RegisterCompany");
            }
            if (reuslt == 1)
            {
                return RedirectToAction("RegisterSuccess");
            }
            else
            {
                return RedirectToAction("RegisterFault");
            }
        }
        public ActionResult RegisterSuccess()
        {
            return View();
        }
        public ActionResult RegisterFault()
        {
            return View();
        }
        public ActionResult RegisterCompany()
        {
            return View();
        }
    }
}
